package com.woniuxy.controller;

import com.woniuxy.entity.Course;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.dto.CourseDto;
import com.woniuxy.service.CourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：杜昊男
 * @Date：2022/3/7 14:43
 * @Description :实现课程的增删改查
 */
@RequestMapping("course")
@RestController
public class CoursesController {
    @Autowired
    CourseService coursesService;

    /*
     * Description : 增加课程
     * ChangeLog : 1. 创建 (2022/3/7 16:47 [10604]);
     ** @param Course course
     * *  @return ResponseEntity
     */
    @ApiOperation(value = "创建课程")
    @PostMapping("create")
    public ResponseEntity createCourse(@RequestBody CourseDto courseDto) {
        return coursesService.createCourse(courseDto);
    }

    @ApiOperation(value = "逻辑删除课程")
    @DeleteMapping("delete/{id}")
    public ResponseEntity deleteCourse(@PathVariable("id") int id) {
        return coursesService.deleteCourse(id);
    }

    @ApiOperation(value = "更新课程")
    @PutMapping("update")
    public ResponseEntity updateCourse(@RequestBody Course course) {
        System.out.println(course);
        return coursesService.updateCourse(course);
    }

    @ApiOperation(value = "查询课程")
    @PostMapping("find/{currentPage}/{pageSize}")
    public ResponseEntity findCourse(@PathVariable("currentPage") int currentPage, @PathVariable("pageSize") int pageSize, @RequestBody Course course) {
        return coursesService.findCourse(currentPage, pageSize, course);
    }

    @ApiOperation(value = "保存课程进度")
    @PostMapping("/saveCourseTime/{userid}")
    public ResponseEntity saveCourseTime(@PathVariable("userid") int userid, @RequestBody Course course) {
        return coursesService.saveCourseTime(userid, course);
    }

    @ApiOperation(value = "查询课程进度")
    @GetMapping("/findCourseProgressing/{userid}/{courseid}")
    public ResponseEntity findCourseProgressing(@PathVariable("userid") int userid, @PathVariable("courseid") int courseid) {
        return coursesService.findCourseProgressing(userid, courseid);
    }
}
